package datastruct;

public class DesignCircularQueue622 {
    public static class MyCircularQueue {
        int[] q;
        int start;// inclusive
        int end;  // exclusive

        public MyCircularQueue(int k) {
            q = new int[k];
            start = 0;
            end = 0;
        }

        public boolean enQueue(int value) {
            if (!isFull()) {
                q[end % q.length] = value;
                end++;
                return true;
            }
            return false;
        }

        public boolean deQueue() {
            if (!isEmpty()) {
                start++;
                return true;
            }
            return false;
        }

        public int Front() {
            if (!isEmpty()) {
                return q[start % q.length];
            }
            return -1;
        }

        public int Rear() {
            if (!isEmpty()) {
                return q[(end-1) % q.length];
            }
            return -1;
        }

        public boolean isEmpty() {
            return end == start;
        }

        public boolean isFull() {
            return end - start == q.length;
        }
    }
}
